"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var EcsComponent_1 = require("./EcsComponent");
var EcsSystem_1 = require("./EcsSystem");
var EcsWorld_1 = require("./EcsWorld");
var entityCount = 1;
var CommonSystem = /** @class */ (function (_super) {
    __extends(CommonSystem, _super);
    function CommonSystem(world, defaltGroupComps) {
        var _this = _super.call(this, world, defaltGroupComps) || this;
        _this.group2 = null;
        _this.group2 = world.getGroupByClz(Comp.B);
        return _this;
    }
    CommonSystem.prototype.update = function () {
        var _this = this;
        if (this.defaultGroup.entities.length >= 100) {
            console.time("removeEntity");
            this.defaultGroup.forEach(function (entity) {
                entity.component(Comp.A).value = 11;
                entity.component(Comp.A).pos.x = 11;
                _this.world.removeEntity(entity.id);
            });
            console.timeEnd("removeEntity");
            console.log(Object.keys(this.world.entities).length);
        }
        this.defaultGroup.forEach(function (entity) {
            // console.log("defaultGroup", entity.id)
        });
        this.group2.forEach(function (entity) {
            // console.log("group2", entity.id)
        });
        // console.time("addComponent")
        // let count=0
        // for (let index = this.group2.entities.length - 1; index >= 0; index--) {
        //     const element = this.group2.entities[index];
        //     element.addComponent(Comp.A)
        //     count++
        // }
        // console.timeEnd("addComponent")
        // log("addComponent",count)
        for (var index = 0; index < entityCount; index++) {
            var entity = this.world.addEntityWithComps([
                Comp.B,
                Comp.A
            ]);
            console.log("addComponent", entity.component(Comp.A).pos);
        }
    };
    return CommonSystem;
}(EcsSystem_1.EcsSystem));
var Comp;
(function (Comp) {
    var A = /** @class */ (function (_super) {
        __extends(A, _super);
        function A() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            _this.pos = { x: 0, y: 0 };
            return _this;
        }
        __decorate([
            (0, EcsComponent_1.RegObjProp)()
        ], A.prototype, "pos", void 0);
        A = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], A);
        return A;
    }(EcsComponent_1.EcsComponent));
    Comp.A = A;
    var B = /** @class */ (function (_super) {
        __extends(B, _super);
        function B() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 2;
            return _this;
        }
        B = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], B);
        return B;
    }(EcsComponent_1.EcsComponent));
    Comp.B = B;
    var C = /** @class */ (function (_super) {
        __extends(C, _super);
        function C() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            return _this;
        }
        C = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], C);
        return C;
    }(EcsComponent_1.EcsComponent));
    Comp.C = C;
    var D = /** @class */ (function (_super) {
        __extends(D, _super);
        function D() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            return _this;
        }
        D = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], D);
        return D;
    }(EcsComponent_1.EcsComponent));
    Comp.D = D;
    var E = /** @class */ (function (_super) {
        __extends(E, _super);
        function E() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            return _this;
        }
        E = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], E);
        return E;
    }(EcsComponent_1.EcsComponent));
    Comp.E = E;
    var F = /** @class */ (function (_super) {
        __extends(F, _super);
        function F() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            return _this;
        }
        F = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], F);
        return F;
    }(EcsComponent_1.EcsComponent));
    Comp.F = F;
    var G = /** @class */ (function (_super) {
        __extends(G, _super);
        function G() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.value = 0;
            return _this;
        }
        G = __decorate([
            (0, EcsComponent_1.RegComponentType)()
        ], G);
        return G;
    }(EcsComponent_1.EcsComponent));
    Comp.G = G;
})(Comp || (Comp = {}));
var TestWorld = /** @class */ (function (_super) {
    __extends(TestWorld, _super);
    function TestWorld() {
        return _super.call(this) || this;
    }
    TestWorld.prototype.afterEntityCreated = function (entity) {
    };
    TestWorld.prototype.beforeEntityRemove = function (entity) {
    };
    TestWorld.prototype.initSingletons = function () {
    };
    TestWorld.prototype.initEntityTypes = function () {
    };
    TestWorld.prototype.initSystems = function () {
        this.addSystem(new CommonSystem(this, [Comp.A, Comp.B]));
    };
    TestWorld.prototype.init = function () {
        this.enable = true;
        // console.time("addEntityWithComps")
        // for (let index = 0; index < entityCount; index++) {
        //     this.addEntityWithComps(
        //         [
        //             Comp.A,
        //             Comp.B,
        //             Comp.C,
        //             Comp.D,
        //             Comp.E,
        //             Comp.F,
        //             Comp.G,
        //         ]
        //     )
        // }
        // console.timeEnd("addEntityWithComps")
        console.time("addEntitybyPool");
        var pool = this.regEntityPool([
            Comp.A,
            Comp.B,
            Comp.C,
            Comp.D,
            Comp.E,
            Comp.F,
            Comp.G,
        ]);
        for (var index = 0; index < entityCount; index++) {
            this.addEntityByGroupId(pool.groupId);
        }
        console.timeEnd("addEntitybyPool");
    };
    return TestWorld;
}(EcsWorld_1.EcsWorld));
// const world = new TestWorld()
// world.init()
// const interval = 1000 / 60
// setInterval(() => {
//     world.update(interval)
// }, interval)
